<template>
	<view style="background-color: #edf1f4">
		 <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
		<view class="Item">
			<view class="item-link item-content">
				<view v-if="signStatus==0">
					<view class="wp-Item-span">未签收</view>
				</view>
				<view v-else>
					<view class="yp-Item-span">已签收</view>
				</view>
				<!--<div class="item-media"></div>-->
				<view class="item-inner">
					<view class="item-title-row">
						<view class="item-title">资产编码:{{assetCode}}</view>
					</view>
					<view class="item-text">
						<view class="ispan"><image :src="scrbt" class="item-icon-bt" mode=""></image>Key账号</view>
						<view class="span">{{loginName}}</view>
					</view>
					<view class="item-text">
						<view class="ispan"><image :src="scrbt" class="item-icon-bt" mode=""></image>所在城市</view>
						<view class="span">{{currAddress}}</view>
					</view>
					<view class="item-text">
						<view class="ispan"><image :src="scrbt" class="item-icon-bt" mode=""></image>资产编码</view>
						<view class="span" style="margin-right: 60rpx;width: 42%;font-size: 28rpx;">
							<input type="text" v-model="assetCode" placeholder="请输入资产编码或扫描" placeholder-class="inputff"/></view>
					</view>
<view class="item-text" style="background-color: #edf1f4;">
	</view>
					<view class="item-text" style="height: 210rpx;margin-top:80rpx !important;">
						<view class="ispan"><image :src="scrbt" class="item-icon-bt" mode=""></image>请拍摄资产整体图</view>
						
					</view>

				</view>
				<view style="position:absolute;margin-left: 91%;margin-top:-355rpx;">
					<image :src="srcsys" class="item-icon-sys" mode="" @tap="signscanCode"></image>
				</view>
				<view style="position:absolute;margin-left: 83%;margin-top:-110rpx;">
					<image :src="srcstring" class="item-icon" mode="" @tap="stockallimg"></image>
				</view>
			</view>
		</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"	
	var self;
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
						MescrollBody
						,
						MescrollUni
					},
		data() {
			return {
				downOption: {
					native: false,
					beforeEndDownScroll:1000,
					textInOffset:"下拉刷新",
					textOutOffset:"释放刷新",
					textLoading:"加载中..."
					},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						size: 6 // 每页数据的数量,默认10
					},
					noMoreSize: 3, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					},
					toTop:{
						src : "../../static/images/icon-up.png" ,
						offset : 50,
						duration : 300,
						zIndex: 9990,
						right: 20,
						bottom: 120,
						safearea: false,
						width: 72,
						radius: "50%",
						left: null
					},
				},
				model: {},
				loginName: "",
				currAddress: "上海市",
				DocumentId: "",
				AssetId: "",
				images: [],
				//srcstring: "../../static/images/icon-paizhao.png",
				srcstring: "../../static/images/icon-paizhao.png",
				srcsys: "../../static/images/icon-sys-hui.png",
				scrbt:"../../static/images/icon-bitian.png",
				assetStatus:["请选择资产状况","资产完好","资产损坏"],
				index:0,
				assetCode:"",
				signStatus:0
				
			}
		},
		computed: {
			tabHeightVal(){
				return uni.getSystemInfoSync().windowHeight+'px'
			}
			},
		onNavigationBarButtonTap() {
			console.log(this.assetCode);
			if(this.assetCode==""){
				uni.showToast({
					icon: 'none',
					title: '请输入资产编码或扫描'
				});
				return;
			}
			if(this.srcstring.indexOf("icon-paizhao")>-1){
				uni.showToast({
					icon: 'none',
					title: '请拍摄资产图片'
				});
				return;
			}
			const uploadTask = uni.uploadFile({
				url: 'http://120.77.180.230:8633/ServerAPI/AssetUpload_Attachment',
				filePath:this.srcstring,
				name: 'file',
				formData: {
					Code: this.assetCode,
					Description: "资产的整体图",
					Title: this.assetCode
				},
				success: function(uploadFileRes) {
					console.log(uploadFileRes.data);
				}
			});
			uni.request({
				url: 'http://120.77.180.230:8633/ServerAPI/AssetUpload_Update', //查询明细
				data: {
					Code: this.assetCode,
					UserCode: "超级管理员",
					SoreName:this.currAddress
				},
				success: res => {

					if (res.data.successed == true) {
						console.log(123);
						uni.navigateBack({

						});

					} else {
						uni.showToast({
							icon: 'none',
							title: res.data.responseState
						});
					}
				},
				fail: () => {

					uni.showToast({
						icon: 'none',
						title: '网络异常,请稍后重试'
					});
				}
			});



		},
		onLoad(options) {
			//首先将实例指针保存到全局变量 self 方便在异步请求中访问实例本身
			self = this;
			const userinfo = uni.getStorageSync("userinfo");
			this.loginName = userinfo.LoginName;
/*
			uni.getLocation({
				type: 'wgs84',
				success: function(res) {
					//console.log('当前位置的经度：' + res.longitude);
					//console.log('当前位置的纬度：' + res.latitude);
					var point = new plus.maps.Point(res.longitude, res.latitude);
					plus.maps.Map.reverseGeocode(
						point, {},
						function(event) {
							var address = event.address; // 转换后的地理位置
							var point = event.coord; // 转换后的坐标信息
							var coordType = event.coordType; // 转换后的坐标系类型
							var reg = /.+?(省|市|自治区|自治州|县)/g;
							//var reg = /.+?(省|市|自治区|自治州|县)/g;
							self.currAddress = address.match(reg)[0];
						},
						function(e) {}
					);
				}
			});
			*/
		},
		methods: {
			stockallimg() {
				self = this;
				// 只允许通过相机扫码
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['camera'],
					success: function(res) {
						// 预览图片
						this.images = res.tempFilePaths;
						const mysrc = res.tempFilePaths[0];
						self.srcstring = mysrc;
						uni.setStorage({
							key: this.assetCode,
							data: mysrc
						});
						console.log(mysrc);
						
					}
				});
			},
			signscanCode(){
				uni.scanCode({
					onlyFromCamera: true,
					success: function(qrres) {
						//var mymodel = JSON.parse(qrres.result);
						//var myDocumentId=this.DocumentId;
						console.log(qrres.result);
							uni.request({
								url: 'http://120.77.180.230:8633/ServerAPI/Document_GetCK_Detail', //仅为示例，并非真实接口地址。
								data: {
									Asset_Code:qrres.result,
									pageSize: 10000,
									pageIndex:0
								},
								success: res => {
									
									if (res.data.successed == true) {
										var mydata = [];
										var newrows = JSON.parse(res.data.rows);
										for (var i = 0; i < newrows.length; i++) {
											var valueRows = newrows[i].toString().split(',');
											var datarow = {};
											for (var j = 0; j < res.data.columns.length; j++) {
												//alert(_data.columns[j].字段名)
												datarow[res.data.columns[j].字段名] = valueRows[j];
											}
											mydata.push(datarow);
											
										}
										console.log(mydata);
										if(mydata.length>0){
										self.model=mydata[0];
										self.assetCode=mydata[0].Code;
										}
									}
							
								},
								fail: () => {
							
									uni.showToast({
										icon: 'none',
										title: '网络异常,请稍后重试'
									});
								}
							}); 
						}
				});
				},
			previewPictures(item) {
				uni.previewImage({
					current: item,
					urls: this.images
				})
			}
		}

	}
</script>

<style>
	.content {
		background-color:#edf1f4;
	}
	.item-icon-bt{
		width: 30upx;
		height: 30upx;
	}
	.item-icon-sys {
		width: 40upx;
		height: 40upx;
	}
	
	.item-icon {
		width: 100upx;
		height: 100upx;
	}

	.Item {
		overflow: hidden;
		border-radius: 16rpx;
		background: #fff;
		
	}

	.item-text {
		border-bottom: 1px solid #e6e6e6;
		margin-right:  .8rem;
		margin-left:  .8rem;

	}

	.item-text .span {
		display: inline-block;
		width: 50%;
		float: right;
		margin-bottom: 10rpx;
		text-align: right;
		color: #BEBEBE;
	}

	.item-text .ispan {
		font-style: normal;
		width: 43%;
		display: inline-block;
		margin-bottom: 10rpx;
	}
	.Item input{
			color: #BEBEBE;
			font-size:30rpx;
		}
	　　.inputff{
			color: #BEBEBE;
			font-size:30rpx;
		}


	.item-content {
		padding-left: 0;
	}

	.item-title .ispan {
		font-size: 30rpx;
		width: auto;
		height: auto;
	}

	.item-title {
		font-size: 30rpx;
		color: #454545;
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		margin-left: 110rpx;
	}
	
	.item-title-row {
		background-image: none;
		margin-right: .8rem;
		border-bottom: 1px solid #e6e6e6;
		background-color: #F4F5F6;
		margin-left: .8rem;
	}	

	.item-link .item-inner {
		padding-right: 0;

	}

	.page-content {
		padding-top: 0;
	}

	.item-text {
		font-size: 30rpx;
		color: #454545;
		padding: 20rpx 0;
		padding-left: 0rpx;
		line-height: 1.2;
	}

	.btext {
		font-weight: normal;
		color: #F79D63;
	}

	.scroll-view_H {
		white-space: nowrap;

		.scroll-view-item_H {
			display: inline-block;
			width: 100%;
			height: 100px;
		}

		.uni-bg-red {
			background: red;
		}

		.uni-bg-green {
			background: green;
		}

		.uni-bg-blue {
			background: blue;
		}
	}

	.yp-Item-span {
		position: absolute;
		width: 50rpx;
		background-color: #BEBEBE;
		font-size: 25rpx;
		padding: 0 10rpx;
		margin-right: 10rpx;
		text-align: center;
		margin-left: 200rpx;
		margin-top: 24rpx;
		color:#FFFFFF;
	}
	.wp-Item-span {
		position: absolute;
		width: 50rpx;
		background-color: #6D8AF9;
		font-size: 25rpx;
		padding: 0 10rpx;
		margin-right: 10rpx;
		text-align: center;
		margin-left: 200rpx;
		margin-top: 24rpx;
		color:#FFFFFF;
	}
	.yp-Item-span {
		position: absolute;
		width: 80rpx;
		background-color: #BEBEBE;
		font-size: 25rpx;
		padding: 0 10rpx;
		margin-right: 10rpx;
		text-align: center;
		margin-left: 35rpx;
		margin-top: 24rpx;
		color:#FFFFFF;
		border-radius:8rpx;
	}
	.wp-Item-span {
		position: absolute;
		width: 80rpx;
		background-color: #6D8AF9;
		font-size: 25rpx;
		padding: 0 10rpx;
		margin-right: 10rpx;
		text-align: center;
		margin-left: 35rpx;
		margin-top: 24rpx;
		color:#FFFFFF;
		border-radius:8rpx;
	}
</style>